/*******************************************************************************
Replication Materials for Blau, Kahn, Brummund, Cook, and Larson-Koester "Is 
There Still Son Preference in the United States?"

Figure 1

Date Modified: 10/21/2019

*******************************************************************************/




*-------------------------------------------------------------------------------
                                   *LOAD DATA
*-------------------------------------------------------------------------------
use "$acs\acs_data", clear 

*-------------------------------------------------------------------------------
                                 *RESTRICT SAMPLE
*-------------------------------------------------------------------------------
keep if nonusbirth == 0 & multi_sample != 1 & mult == 0 & oldc <=12 & ///
	inrange(age,18,40)==1 & nchild18>=1 
drop if citizen==1 | marst == 5
drop if marst == 5


*-------------------------------------------------------------------------------
                          *GENERATE DM (2008) VARIABLES
*-------------------------------------------------------------------------------

// RACE:
gen dmrace=0 if inlist(raced,100,120)==1 //White
replace dmrace = 1 if inlist(raced,200,210,801,917,985,986,990)==1 ///
					| inrange(raced,830,845)==1 ///
					| inrange(raced,901,904)==1 ///
					| inrange(raced,930,935)==1 ///
					| inrange(raced,950,955)==1 ///
					| inrange(raced,970,973)==1 ///
					| inrange(raced,980,983)==1
replace	dmrace = 2 if (inlist(raced,902,905,910,933,934,940,941,943,944,950,953,954,960,961)==1 ///
					| inrange(raced,400,679)==1 ///
					| inrange(raced,810,819)==1 ///
					| inrange(raced,831,838)==1 ///
					| inrange(raced,850,854)==1 ///
					| inrange(raced,860,887)==1 ///
					| inrange(raced,910,923)==1 ///
					| inrange(raced,926,930)==1 ///
					| inrange(raced,963,971)==1 ///
					| inrange(raced,973,981)==1 ///
					| inrange(raced,983,986)==1) & dmrace==.
replace dmrace = 3 if dmrace==.
label define dmrace_lbl 0 "White" 1"Black" 2"Asian" 3"Other"
label val dmrace dmrace_lbl		

// EDUCATION:
gen college = scol + cold // combined college variable

*-------------------------------------------------------------------------------
                    *SET UP EXCEL FILE THAT WILL STORE ESTIMATES
*-------------------------------------------------------------------------------
putexcel set "$foutput\figure1_data", replace
putexcel A1 = "year" 
putexcel B1 = "coeff" 
putexcel A2 = "1960"
putexcel A3 = "1970"
putexcel A4 = "1980"
putexcel A5 = "1990"
putexcel A6 = "2000"
putexcel A7 = "2008-2013"



*-------------------------------------------------------------------------------
                               *REGRESSION
*-------------------------------------------------------------------------------
local controls "lths college i.cohort" //leave out: hsdi
local controls "`controls' i.dmrace i.region age age2 age3"
local wgt "perwtnorm"
reg femhdalt chld1 `controls' [aw=`wgt'],  robust
return list
local coef = r(table)[1, 1]
putexcel B7 = `coef'

*-------------------------------------------------------------------------------
                       *DM (2008) ESTIMATES TO 4 DECIMAL PLACES
*-------------------------------------------------------------------------------
use "$dm\sons-census", clear 
local i = 2
foreach groupvar of varlist year60 year70 year80 year90 year00 {
  di " "
  di "***** " "`groupvar'" " *****"
  quietly replace insamp=marst!=5 & `groupvar'==1
  reg nodad ksex1 dd* black white asian educ1 educ2 age age2 age3 born* [pweight=perwt] if insamp
  return list
  local coef = r(table)[1, 1]
  di `coef'
  putexcel B`i' = `coef'
  local i = `i' + 1
}


*-------------------------------------------------------------------------------
					             *FIGURE CODE
*-------------------------------------------------------------------------------
import excel "$foutput\figure1_data", clear firstrow
replace coeff = coeff*100
replace coeff = round(coeff, 0.0001)
format coeff  %5.4f
graph bar coeff, over(year, gap(*.7)) bar(1, color(gs8) lwidth(thick)) ///
	ytitle("Percentage Point Effect of First Child Girl") ///
	graphregion(color(white)) bgcolor(white)  blabel(bar,  format(%5.4f))
graph export "$foutput\figure1.png", replace






